//
//  FansLogic.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/1.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "FansLogic.h"

@implementation FansLogic
- (instancetype)init
{
    self = [super init];
    if (self) {
        _page = 0;
        _dataArray = [NSMutableArray array];
    }
    return self;
}

-(void)loadData
{
    if (_page == 0) {
        [_dataArray removeAllObjects];
    }
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_follow_list"];
    if(self.type == CYFansTypeAttr)
    {
        url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_follow_list"];
    }
    else if(self.type == CYFansTypeFans)
    {
        url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_fans_list"];
    }

    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@(_page) forKey:@"page"];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if (_page == 0) {
            [_dataArray removeAllObjects];
        }
        
        NSArray *tmpArr = [NSMutableArray modelArrayWithClass:[FansModel class] json:[responseObject valueForKey:@"data"]];
        NSMutableArray *list = [NSMutableArray arrayWithArray:tmpArr];
        
        [_dataArray addObjectsFromArray:list];
        
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error) {
//        [MBProgressHUD showTipMessageInWindow:error];
//        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
//            [self.delegagte requestDataCompleted];
//        }
    } hasCache:YES];
}

@end


